import 'package:ati_package/core/routes/app_routes.dart';
import 'package:ati_package/core/utils/ati_assets.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/pages/common/ati_scaffold.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../widgets/trend_header_widget.dart';
import '../widgets/trend_list_widget.dart' hide Post;
import '../widgets/trend_userlist_widget.dart';

class UserTrendView extends StatefulWidget {
  const UserTrendView({super.key});

  @override
  State<UserTrendView> createState() => _TrendViewState();
}

class _TrendViewState extends State<UserTrendView> {
  @override
  Widget build(BuildContext context) {
    return AtiScaffold(
      extendBodyBehindAppBar: true,
      barBgColor: Colors.transparent,
      title: '动态详情',
      rigthOnTap: () => Get.toNamed(AtiAppRoutes.trendSetting),
      body: Stack(children: [buildBgImage(), buildContextWidgets()]),
    );
  }

  buildBgImage() {
    return Container(
      height: 256.r,
      width: double.infinity,
      decoration: BoxDecoration(
        // gradient: LinearGradient(
        //   colors: [Color(0xFFB3E5FC), Color(0xFFC8E6C9)],
        //   begin: Alignment.topCenter,
        //   end: Alignment.bottomCenter,
        // ),
        image: DecorationImage(
          image: AssetImage(AtiAssets.trendBg, package: 'ati_package'),
          fit: BoxFit.cover,
        ),
      ),
    );
  }

  buildContextWidgets() {
    // 示例数据（模拟）
    List<Post> _generatePosts() {
      return List.generate(6, (i) {
        final imgs = List.generate(
          (i % 3) + 1,
          (j) => 'https://picsum.photos/seed/${i * 10 + j}/400/400',
        );
        return Post(
          avatar: 'https://picsum.photos/seed/avatar$i/80',
          username: '用户$i',
          time: '2025/06/20 17:17:${40 + i}',
          text: '这是第 $i 条动态，示例文字内容。可换成真实数据，支持多行展示。',
          images: imgs,
          likes: 12500 + i * 10,
          commentsCount: 8 + i,
          comments: List.generate(8 + i, (k) => 'user$k：这是评论内容 $k'),
        );
      });
    }

    final posts = _generatePosts();

    return SafeArea(
      bottom: false,
      child: SingleChildScrollView(
        child: Column(
          children: [
            _buildHeaderWidget(),
            Container(
              color: AtiColor.pageColor,
              child: ListView.builder(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                padding: const EdgeInsets.symmetric(
                  vertical: 12,
                  horizontal: 12,
                ),
                itemCount: posts.length,
                itemBuilder: (context, index) => PostCard1(post: posts[index]),
              ),
            ),
          ],
        ),
      ),
    );
  }

  _buildHeaderWidget() {
    return TrendHeaderWidget(
      isMyTrend: true,
      backgroundUrl: 'https://picsum.photos/800/400?blur', // 背景图
      avatarUrl: 'https://picsum.photos/800/400?blur', // 头像
      username: '开荒者',
      signature: '个性签名展示区个性签名展示区个性签名展示区',
      onEdit: () => Get.toNamed(AtiAppRoutes.trendPublish),
      onChangeAvatar: () => print('更换头像'),
      onChangeBackground: () => Get.toNamed(AtiAppRoutes.trendPublish),
    );
  }
}
